﻿using System;
using fastCSharp;

namespace diantou.examLogServer
{
    /// <summary>
    /// 考试日志服务
    /// </summary>
    class console : fastCSharp.diagnostics.consoleLog
    {
        /// <summary>
        /// 考试日志服务
        /// </summary>
        private diantou.examLogServer.tcpServer.ExamLog server;
        /// <summary>
        /// 当前进程是否正在尝试忽略考试日志服务端操作
        /// </summary>
        private bool isTryIgnoreServer;
        /// <summary>
        /// 启动考试日志服务
        /// </summary>
        protected override void start()
        {
            if (fastCSharp.sql.connection.IsCheckConnection) examLog();
            else output("没有找到可用的数据库连接信息");
        }
        /// <summary>
        /// 启动考试日志服务
        /// </summary>
        private void examLog()
        {
            bool isStart = false;
            try
            {
                if (isStart = (server = new diantou.examLogServer.tcpServer.ExamLog()).Start()) setTcpIgnoreGroup(() => server, () => isTryIgnoreServer);
            }
            catch (Exception error)
            {
                output(error);
            }
            output("ExamLog " + isStart.ToString());
            if (!isStart)
            {
                server = null;
                fastCSharp.threading.timerTask.Default.Add(examLog, date.NowSecond.AddSeconds(2));
            }
        }
        /// <summary>
        /// 关闭考试日志服务
        /// </summary>
        protected override void dispose()
        {
            pub.Dispose(ref server);
        }
    }
}
